package com.hdd.fmh.common.bean;

import com.hdd.fmh.common.utils.StringUtils;
import com.hdd.fmh.module.sys.utils.UserUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;

/**
 * @Description: 数据Entity类
 * @author Jiahang
 */
@Data
public abstract class BaseEntity extends AbstractBaseEntity{

    private static final long serialVersionUID = 1L;
    @ApiModelProperty(value = "备注", name = "remarks")
    protected String remarks;
    @ApiModelProperty(value = "创建者", name = "createBy")
    protected Integer createBy;
    @ApiModelProperty(value = "创建日期", name = "createDate")
    protected Date createDate;
    @ApiModelProperty(value = "更新者", name = "updateBy")
    protected Integer updateBy;
    @ApiModelProperty(value = "更新日期", name = "updateDate")
    protected Date updateDate;

    /**
     * 插入之前执行方法，需要手动调用
     */
    @Override
    public void preInsert() throws Exception {
        Integer uid = UserUtils.getUserIdByToken();
        if(!StringUtils.isNullOrEmpty(uid)) {
            this.updateBy  = uid;
            this.createBy = uid;
            this.delFlag = DEL_FLAG_NORMAL;
        }
        this.updateDate = new Date();
        this.createDate = this.updateDate;
    }	/**
     * 插入之前执行方法，需要手动调用
     */

    /**
     * 更新之前执行方法，需要手动调用
     */
    @Override
    public void preUpdate() throws Exception {
        Integer uid = UserUtils.getUserIdByToken();
        if(!StringUtils.isNullOrEmpty(uid)) {
            this.updateBy  = uid;
        }
        this.updateDate = new Date();
    }
}